package com.ssy.lingxi.platform.template.service.serviceimpl.mobile;

import com.ssy.lingxi.common.exception.BusinessException;
import com.ssy.lingxi.common.response.ResponseCode;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.template.service.constant.ActivityPageStatusEnum;
import com.ssy.lingxi.platform.template.service.entity.adorn.ActivityPage;
import com.ssy.lingxi.platform.template.service.model.dto.common.IdDTO;
import com.ssy.lingxi.platform.template.service.repository.ActivityPageRepository;
import com.ssy.lingxi.platform.template.service.service.mobile.ActivityPageMobileService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @menu mobile - 活动页 - 业务实现层
 * @author fhj
 * @version 2.0.0
 * @date 2021/09/07
 */
@Slf4j
@Service
public class ActivityPageMobileServiceImpl implements ActivityPageMobileService {

    @Resource
    private ActivityPageRepository activityPageRepository;

    @Override
    @ApiOperation(value = "详情")
    public Wrapper<ActivityPage> get(IdDTO dto) {
        ActivityPage activityPage = activityPageRepository.findById(dto.getId()).orElse(null);
        if(activityPage == null) {
            throw new BusinessException(ResponseCode.PT_RECORDS_DON_T_EXIST);
        }
        if(activityPage.getStatus().equals(ActivityPageStatusEnum.WAIT_OPEN_LINE.getCode())
                || activityPage.getStatus().equals(ActivityPageStatusEnum.ALREADY_OPEN_LINE.getCode())) {
            return Wrapper.fail(ResponseCode.PT_THE_EVENT_HAS_NOT_STARTED_YET);
        }
        if(activityPage.getStatus().equals(ActivityPageStatusEnum.OFF_LINE.getCode())
                || activityPage.getStatus().equals(ActivityPageStatusEnum.END.getCode())) {
            return Wrapper.fail(ResponseCode.PT_THE_EVENT_IS_OVER);
        }
        return Wrapper.success(activityPage);
    }
}
